﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FacebookApp;
using System.Data;

public partial class Pages_ListSaleOff : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dlListProduct.DataSource = EbookService.Ebook_GetByTop("16", " [Status]='True' and PriceNew <> 0 ", " PriceNew ");
            dlListProduct.DataBind();

        }
    }

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string strCA = e.CommandArgument.ToString();
        if (e.CommandName == "Choose")
        {
            AddCart(e.CommandArgument.ToString(), "1");
        }
        else
        {
            Ebook dt = EbookService.Ebook_GetById(strCA);
            string Category_Id = dt.Category_Id.ToString();
            string URL = "/Pages/ProductDetail.aspx?Catogory_Id =" + Category_Id + "&Id=" + strCA;
            Response.Redirect(URL);
        }
    }

    public string Format_Price(string s)
    {
        return FunctionClass.Format_Price(s);
    }

    public string CatChu(string s)
    {
        return FunctionClass.CatChu(s);
    }

    protected void AddCart(string productid, string quantity)
    {
        if (Session["Cart"] == null)
            Session["Cart"] = FunctionClass.AddCart(productid, quantity, null);
        else
            Session["Cart"] = FunctionClass.AddCart(productid, quantity, (DataTable)Session["Cart"]);
    }
}